package Niuke;


//阿里面试题 求过！！！！！


//给定一个字符串如“This is a coding test”，请使用两个线程交叉向屏幕打印这个字符串。
        // TODO

import sun.jvm.hotspot.opto.Block;

//、2、输入2个数字字符串，每个字符串超过200字符，请输出相加后的结果。
// TODO
public class Ali {


    static volatile int state=0;
    static final Object lock=new Object();
    public static void main(String[] args) {
        new Thread(()->{
            for (int i=0;i<10;i++) {
                synchronized (lock) {
                    while (state == 0) {
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("t1---his is a coding test");
                    state = 0;
                    lock.notifyAll();
                }
            }
        }).start();
        new Thread(()->{
            for (int i=0;i<10;i++) {
                synchronized (lock) {
                    while (state == 1) {
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    System.out.println("t2---his is a coding test");
                    state = 1;
                    lock.notifyAll();
                }
            }
        }).start();
    }
}
